<!--物料设置->物料档案-->
<template>
    <div class="content-wrapper a-base-container">
        <div class="big-main-wrapper">
            <div class="btn-wrapper clearfix">
                <a-row class="text-center clearfix">
                    <a-col :xs="24" :sm="24" :md="24" :lg="16" :xl="12">
                        <a-col :span="2" v-if="permissions.includes('inventory:add')">
                            <div class="btns" @click="add">
                                <a-icon class="btns-icon" type="file-add" />
                                <div class="btns-text">新增</div>
                            </div>
                        </a-col>
                        <a-col :span="2" v-if="permissions.includes('inventory:edit')">
                            <div class="btns" @click="edit">
                                <a-icon class="btns-icon" type="edit" />
                                <div class="btns-text">修改</div>
                            </div>
                        </a-col>
                        <a-col :span="2" v-if="permissions.includes('inventory:delete')">
                            <div class="btns" @click="remove">
                                <a-icon class="btns-icon" type="delete" />
                                <div class="btns-text">删除</div>
                            </div>
                        </a-col>
                        <a-col :span="2">
                            <div class="btns" @click="importData">
                                <a-icon class="btns-icon" type="import" />
                                <div class="btns-text">导入</div>
                            </div>
                        </a-col>
                        <a-col :span="2">
                            <div class="btns" @click="exportData">
                                <a-icon class="btns-icon" type="export" />
                                <div class="btns-text">导出</div>
                            </div>
                        </a-col>
                        <a-col :span="2">
                            <div class="btns" @click="qrCodePrint">
                                <a-icon class="btns-icon" type="qrcode" />
                                <div class="btns-text">二维码打印</div>
                            </div>
                        </a-col>
                        <a-col :span="2">
                            <div class="btns" @click="syncFun">
                                <a-icon class="btns-icon" type="sync" />
                                <div class="btns-text">刷新</div>
                            </div>
                        </a-col>
                    </a-col>
                </a-row>
            </div>
            <div class="content-tree-wrapper">
                <div class="tree-box" style="position:relative;padding-top:10px;">
                    <!-- <div class="archive-tree-refresh" @click="calssList" title="刷新">
                        <a-icon type="sync"/>
                    </div> -->
                    <a-tree class="tree" show-line v-if="treeData.length > 0" :tree-data="treeData" :replaceFields="replaceFields" defaultExpandAll @select="treeSelect">
                        <a-icon slot="switcherIcon" type="down" />
                    </a-tree>
                </div>
                <div class="resize-table-container">
                    <a-table id="archives_setting_tb" :columns="columns" :scroll="{ x: 600, y: 400 }" :data-source="tableData" bordered :pagination="pagination" :customRow="customClick" :row-selection="{columnWidth: 26,selectedRowKeys: selectedRowKeys,onChange: onSelectChange,}">
                        <template slot="unitName" slot-scope="text">
                            <div>
                                {{text}}
                            </div>
                        </template>

                        <div slot="filterDropdown" slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }" style="padding: 8px">
                            <a-input v-model="tableSearchName" :placeholder="`搜索${column.title}`" style="width: 188px; margin-bottom: 8px; display: block;margin-right: 8px" @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])" @pressEnter="() => handleSearch(selectedKeys, confirm, column.dataIndex)" />
                            <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">
                                重置
                            </a-button>
                            <a-button class="margin-left-10" type="primary" icon="search" size="small" style="width: 90px;" @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)">
                                搜索
                            </a-button>
                        </div>
                        <div slot="filterDropdownCode" slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }" style="padding: 8px">
                            <a-input v-model="tableSearchCode" :placeholder="`搜索${column.title}`" style="width: 188px; margin-bottom: 8px; display: block;margin-right: 8px" @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])" @pressEnter="() => handleSearch(selectedKeys, confirm, column.dataIndex)" />
                            <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">
                                重置
                            </a-button>
                            <a-button class="margin-left-10" type="primary" icon="search" size="small" style="width: 90px;" @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)">
                                搜索
                            </a-button>
                        </div>
                        <div slot="filterDropdownG" slot-scope="{ setSelectedKeys, selectedKeys, confirm, clearFilters, column }" style="padding: 8px">
                            <a-input v-model="inventorySpecificationSearch" :placeholder="`搜索${column.title}`" style="width: 188px; margin-bottom: 8px; display: block;margin-right: 8px" @change="e => setSelectedKeys(e.target.value ? [e.target.value] : [])" @pressEnter="() => handleSearch(selectedKeys, confirm, column.dataIndex)" />
                            <a-button size="small" style="width: 90px" @click="() => handleReset(clearFilters)">
                                重置
                            </a-button>
                            <a-button class="margin-left-10" type="primary" icon="search" size="small" style="width: 90px;" @click="() => handleSearch(selectedKeys, confirm, column.dataIndex)">
                                搜索
                            </a-button>
                        </div>
                        <a-icon slot="filterIcon" type="filter" theme="filled" :style="{ color: '#444',marginRight:'5px' }" />
                        <a-icon slot="filterIconCode" type="filter" theme="filled" :style="{ color: '#444',marginRight:'5px' }" />
                    </a-table>
                </div>
            </div>
            <drag-modal v-model="editModal" :title="'物料档案'" width="1100px" @ok="handleSubmit" :okText="'保存'" @cancel="handleCancel" :cancelText="'关闭'" class="archives-flag" :footer="null">
                <div class="big-main-wrapper" style="border:0px;">
                    <div class="btn-wrapper clearfix" style="border-bottom:1px solid #ccc;">
                        <a-row class="text-center clearfix">
                            <a-col :xs="24" :sm="24" :md="24" :lg="18" :xl="18">
                                <a-col :span="2" v-if="permissions.includes('inventory:save')">
                                    <div class="btns" @click="handleSubmit">
                                        <a-icon class="btns-icon" type="save" />
                                        <div class="btns-text">保存</div>
                                    </div>
                                </a-col>
                                <a-col :span="2" v-if="permissions.includes('inventory:save')">
                                    <div class="btns" @click="handleSubmit(1)">
                                        <a-icon class="btns-icon" type="file-add" />
                                        <div class="btns-text">保存并新增</div>
                                    </div>
                                </a-col>
                                <a-col :span="2" v-if="permissions.includes('inventory:save')">
                                    <div class="btns" @click="handleSubmit(2)">
                                        <a-icon class="btns-icon" type="file-add" />
                                        <div class="btns-text">保存并复制</div>
                                    </div>
                                </a-col>
                                <a-col :span="2" v-if="copyBtn">
                                    <div class="btns" @click="deleteId">
                                        <a-icon class="btns-icon" type="copy" />
                                        <div class="btns-text">复制</div>
                                    </div>
                                </a-col>
                                <a-col :span="2">
                                    <div class="btns" @click="page(3)">
                                        <a-icon class="btns-icon" type="vertical-right" />
                                        <div class="btns-text">首张</div>
                                    </div>
                                </a-col>

                                <a-col :span="2">
                                    <div class="btns" @click="page(1)">
                                        <a-icon class="btns-icon" type="left" />
                                        <div class="btns-text">上张</div>
                                    </div>
                                </a-col>

                                <a-col :span="2">
                                    <div class="btns" @click="page(2)">
                                        <a-icon class="btns-icon" type="right" />
                                        <div class="btns-text">下张</div>
                                    </div>
                                </a-col>

                                <a-col :span="2">
                                    <div class="btns" @click="page(4)">
                                        <a-icon class="btns-icon" type="vertical-left" />
                                        <div class="btns-text">末张</div>
                                    </div>
                                </a-col>
                            </a-col>
                        </a-row>
                    </div>
                </div>

                <a-form-model class="ant-advanced-search-form" :model="fromCommonData" :form="form" ref="ruleForm" :label-col="{ span: 10 }" :wrapper-col="{ span: 14 }">
                    <div id="components-form-demo-advanced-search">
                        <dynamicForm :FormData="fromCommonData">
                            <!--物料分类-->
                            <template v-slot:search="{code}">
                                <div v-for="(key,index) in fromCommonData" :key="index">
                                    <div v-if="key.code == code">
                                        <a-input read-only v-if="code =='inventoryCategoryId'" :placeholder="`选择${key.name}`" v-model="key.valueName" @click="selectModalShow(key.code)" />
                                        <a-input read-only v-if="archivesId == null && code =='inventoryClassId'" :placeholder="`选择${key.name}`" v-model="key.valueName" @click="selectModalShow(key.code)" />
                                        <a-input v-else-if="code =='inventoryClassId'" v-model="key.valueName" disabled />
                                    </div>
                                </div>
                                <inventoryModal ref="invenRef" @setValue="setValue"></inventoryModal>
                                <inventoryAfterModal ref="invenAfterRef" @setValue="setValue"></inventoryAfterModal>
                            </template>
                            <!--物料名称-->
                            <template v-slot:inventoryName="{item}">
                                <a-input :disabled="!item.onEdit" v-model="item.valueName" :placeholder="`请输入${item.name}`" @change="inventoryChange" />
                            </template>
                            <!--物料编码-->
                            <template v-slot:inventoryCode="{item}">
                                <a-input-group v-if="archivesId == null" compact style="display:flex;width:204.5px;height:32px;">
                                    <span class="input-group-before">{{item.valueName}}</span>
                                    <a-input class="input-group-after" style="height:32px;line-height:32px;" v-model="afterCode" />
                                </a-input-group>
                                <a-input v-else disabled v-model="item.valueName" />
                            </template>
                            <!--规格型号-->
                            <template v-slot:inventorySpecification="{item}">
                                <a-input :disabled="!item.onEdit" v-model="item.valueName" :placeholder="`请输入${item.name}`" />
                            </template>
                        </dynamicForm>

                        <a-tabs slot="after" class="wh100" :activeKey="activeKey" default-active-key="1" @change="callback">
                            <a-tab-pane key="1" tab="基本信息">
                                <card-wrapper v-if="isRouterAlive">
                                    <template v-slot:slot-1>
                                        <dynamicForm :FormData="fromBasicData" @jlselect="jlselect">
                                            <!--所属营销机构-->
                                            <template v-slot:search="{code}">
                                                <div v-for="(key,index) in fromBasicData" :key="index">
                                                    <div v-if="key.code == code">
                                                        <a-input :disabled="!key.onEdit" :placeholder="`选择${key.name}`" style="width: 198px" :prop="key.code" v-model="key.valueName" @click="selectModalShow(key.code)" />
                                                    </div>
                                                </div>
                                                <officeModal ref="agenciesRef" @setValue="setValue" :title="'所属营销机构'"></officeModal>
                                            </template>

                                            <!--特殊处理的数据-->
                                            <template v-slot:unitType="{code}">
                                                <div v-for="(key,index) in fromBasicData" :key="index">
                                                    <a-select v-if="key.code == code" :disabled="!key.onEdit" :placeholder="`请选择${key.name}`" :prop="key.code" v-model="key.valueId" @change="unitTypeChange" :rules="[{ required: key.onFill, message: `${key.name}必须选择` }]">
                                                        <a-select-option v-for=" (select,index) in formatVal(key.val)" :key="index+'select'" :value="select.id">
                                                            {{select.name}}
                                                        </a-select-option>
                                                    </a-select>
                                                </div>
                                            </template>
                                            <template v-slot:unitIdAll>
                                                <!--计量单位-->
                                                <div v-for="(key,index) in fromBasicData" :key="index">
                                                    <unitDropDownSearch v-if="key.code=='unitId'" ref="unitRef" v-show="key.isShow" :incomingData="key" @okUnit="okUnit"></unitDropDownSearch>
                                                    <unitsDropDownSearch v-if="key.code=='unitGroupId'" ref="unitGroupRef" v-show="key.isShow" :incomingData="key" @okUnit="okUnit">
                                                    </unitsDropDownSearch>
                                                </div>
                                            </template>
                                        </dynamicForm>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="2" :disabled="moreOrLittle==0" tab="计量单位组">
                                <!-- 多计量换算率表格 -->
                                <a-table class="unitGroupTable" :columns="unitGroupColumns" :data-source="detailsTableData" bordered :pagination="false">
                                    <template slot="indexNumber" slot-scope="text, record, index">
                                        {{index + 1}}
                                    </template>
                                    <template slot="isMainUnit" slot-scope="text">
                                        <a-checkbox :checked="text"></a-checkbox>
                                    </template>
                                    <template slot="convertType" slot-scope="text,record">
                                        {{text==0 && !record.isMainUnit?'固定':  !record.isMainUnit ? '浮动':''}}
                                    </template>
                                    <template slot="changeRate" slot-scope="text, record">
                                        {{record.changeRate}}
                                        <!-- <a-input-number :disabled="record.isMainUnit" @change="changeRate" auto-size style="width:80px" v-model="record.changeRate"></a-input-number> -->
                                    </template>
                                </a-table>
                            </a-tab-pane>
                            <a-tab-pane key="3">
                                <span slot="tab">
                                    <span style="display: inline-block;margin-right: 4px;color: #f5222d;font-size: 14px;font-family: SimSun,sans-serif;line-height: 1;content: '*'';">*</span>物料属性
                                </span>
                                <!-- 物料属性 -->
                                <card-wrapper v-if="isShowFromYesNoData">
                                    <template v-slot:slot-1>
                                        <a-row :gutter="24">
                                            <a-col :span="24" class="text-center">
                                                <dynamicForm :FormData="fromYesNoData" :inventoryAttributMutexe="inventoryAttributMutexe"></dynamicForm>
                                            </a-col>
                                        </a-row>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="10">
                                <span slot="tab">
                                    商品属性
                                </span>
                                <!-- 商品属性 -->
                                <card-wrapper>
                                    <template v-slot:slot-1>
                                        <a-row :gutter="24" class="good-attr-wrapper">
                                            <a-col :span="24" class="text-center">
                                                <!-- <dynamicForm :FormData="fromCommodityData" :inventoryAttributMutexe="inventoryAttributMutexe"></dynamicForm> -->

                                                <a-row :gutter="6" style="margin-bottom:10px">
                                                    <a-col :span="3">
                                                        属性名称
                                                    </a-col>
                                                    <a-col :span="8">
                                                        备选值
                                                    </a-col>
                                                </a-row>
                                                <a-input-group v-for="(item,index) in commodityData" :key="item" style="margin-bottom:10px">
                                                    <a-row :gutter="6" style="text-align:left;">
                                                        <a-col :span="3">
                                                            <a-input v-model="item.key" @blur="checkCommodityKey" />
                                                        </a-col>
                                                        <a-col :span="8">
                                                            <a-input v-model="item.value" />
                                                        </a-col>
                                                        <a-col :span="2" class="delete-good-attr" v-if="commodityData.length > 1" @click="deleteCommodityData(index)">
                                                            <a-icon type="close" />
                                                        </a-col>
                                                    </a-row>
                                                </a-input-group>
                                                <div class="add-good-attr" @click="addCommodityData">
                                                    <a-icon type="plus" />
                                                </div>
                                            </a-col>
                                        </a-row>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="11">
                                <span slot="tab">
                                    重量/尺寸信息
                                </span>
                                <!-- 重量.尺寸信息 -->
                                <card-wrapper>
                                    <template v-slot:slot-1>
                                        <a-row :gutter="24">
                                            <a-col :span="24" class="text-center">
                                                <dynamicForm :FormData="fromWeightData" :inventoryAttributMutexe="inventoryAttributMutexe"></dynamicForm>
                                            </a-col>
                                        </a-row>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="4" tab="库存信息">
                                <card-wrapper>
                                    <template v-slot:slot-1>
                                        <dynamicForm :FormData="fromInventoryData">
                                            <template v-slot:search="{code}">
                                                <div v-for="(key,index) in fromInventoryData" :key="index">
                                                    <!-- {{key.code}}<br>
                                                {{code}} -->
                                                    <div v-if="key.code == code">
                                                        <a-input-search :placeholder="`选择${key.name}`" style="width: 198px" v-model="key.valueName" @click="selectModalShow(key.code)" />
                                                    </div>
                                                </div>
                                                <!--仓库-->
                                                <warehouseModal ref="warehouseRef" @setValue="setValue"></warehouseModal>
                                                <!--货位-->
                                                <warehouseGoodsModal ref="locationRef" :id="locationId" @setValue="setValue"></warehouseGoodsModal>
                                            </template>
                                        </dynamicForm>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="5" tab="控制">
                                <card-wrapper>
                                    <template v-slot:slot-1>
                                        <dynamicForm :FormData="fromControlData">
                                            <!--盘点开始时间-->
                                            <template v-slot:startCountTime="{code}">
                                                <div v-for="(key,index) in fromControlData" :key="index">
                                                    <div v-if="key.code == code">
                                                        <a-date-picker :disabled="!key.onEdit" @change="onChangeTimeA" style="width: 180px;min-width:180px;" format="YYYY-MM-DD HH:mm" :prop="key.code" v-model="key.valueId" :rules="[{ required: key.onFill, message: `${key.name}必须选择` }]" :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }" />
                                                    </div>
                                                </div>
                                            </template>
                                            <!--上次盘点时间-->
                                            <template v-slot:lastCountTime="{code}">
                                                <div v-for="(key,index) in fromControlData" :key="index">
                                                    <div v-if="key.code == code">
                                                        <a-date-picker :disabled="!key.onEdit" @change="onChangeTimeB" style="width: 180px;min-width:180px;" format="YYYY-MM-DD HH:mm" :prop="key.code" v-model="key.valueId" :rules="[{ required: key.onFill, message: `${key.name}必须选择` }]" :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }" />
                                                    </div>
                                                </div>
                                            </template>
                                        </dynamicForm>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="6" tab="二维码">
                                <card-wrapper>
                                    <template v-slot:slot-1>
                                        <div v-if="selectedData[0]">
                                            <div class="archives-barcode-box" id="barCodeBox">
                                                <div class="company-name">
                                                    {{userInfo.companyName}}
                                                </div>
                                                <div class="barcode-item">
                                                    <div class="bar-name">物料编码</div>
                                                    <div class="bar-text">{{selectedData[0].inventoryCode}}</div>
                                                </div>
                                                <div class="barcode-item">
                                                    <div class="bar-name">物料名称</div>
                                                    <div class="bar-text">{{selectedData[0].inventoryName}}</div>
                                                </div>
                                                <div class="barcode-bottom clearfix">
                                                    <div class="barcode-left-wrapper">
                                                        <div class="barcode-left">
                                                            <div class="bar-name">物料分类</div>
                                                            <div class="bar-text bar-text-min">{{selectedData[0].inventoryClassName}}</div>
                                                        </div>
                                                        <div class="barcode-left">
                                                            <div class="bar-name">规格型号</div>
                                                            <div class="bar-text bar-text-min">{{selectedData[0].inventorySpecification}}</div>
                                                        </div>
                                                        <div class="barcode-left" style="border:none">
                                                            <div class="bar-name">计量单位</div>
                                                            <div class="bar-text bar-text-min">{{selectedData[0].mainUnitName?selectedData[0].mainUnitName:selectedData[0].unitName}}</div>
                                                        </div>
                                                    </div>
                                                    <div class="borcode-box">
                                                        <!-- <barcode :value="selectedData[0].inventoryCode" :barWidth="3" :width="2" :textAlign="left" :height="50" :fontSize="14">
                                                        <span style="color:red"> 生成二维码失败</span>
                                                    </barcode> -->
                                                        <vue-qr :text="selectedData[0].inventoryCode" :size="96" :margin="6"></vue-qr>
                                                    </div>
                                                </div>

                                            </div>
                                            <div class="barcode-btn">
                                                <a-button size="small" type="primary" @click="downImg" ghost>下载png</a-button>
                                                <a-button size="small" type="primary" v-print="'#barCodeBox'" class="margin-left-40" ghost>打印二维码</a-button>
                                            </div>
                                            <div id="showBarCode">

                                            </div>
                                        </div>
                                        <span v-else style="font-size:16px;color:rgba(250,4,4,0.8)">保存物料后自动生成二维码</span>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="7" tab="批号管理">
                                <card-wrapper :title="'批号信息'">
                                    <template v-slot:slot-1>
                                        <dynamicForm :FormData="fromBatchData"></dynamicForm>
                                    </template>
                                </card-wrapper>
                            </a-tab-pane>
                            <a-tab-pane key="8" tab="图片">
                                <div>
                                    <a-upload :action="this.$Global.ApiBaseUrl + '/uploadFile'" :headers="headersData" list-type="picture-card" :file-list="fileList" @preview="handlePreview" @change="handleChange">
                                        <div>
                                            <a-icon type="plus" />
                                            <div class="ant-upload-text">
                                                上传图片
                                            </div>
                                        </div>
                                    </a-upload>
                                    <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancelImg">
                                        <img alt="example" style="width: 100%" :src="previewImage" />
                                    </a-modal>
                                </div>
                            </a-tab-pane>
                        </a-tabs>

                    </div>
                </a-form-model>
            </drag-modal>
            <importAndExport ref="importRef" @syncFun="syncFun"></importAndExport>
        </div>
        <!--是否安装打印插件-->
        <barcodeUtil ref="printPlugIn"></barcodeUtil>
    </div>
</template>
<script>
function getBase64 (file) {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => resolve(reader.result);
        reader.onerror = (error) => reject(error);
    });
}

import Vue from "vue";
import { ACCESS_TOKEN } from "@/store/mutation-types";
import { mapState } from "vuex";
import table from "@/mixins/table";
import { list } from "@/api/inventory/inventoryClass"; //获取物料分类树形菜单
import { classPageListToTree, searchInTreeData } from "@/utils/tree";
import { cardWrapper } from "@/components/CardWrapper";
import { list as listDesign, groupList } from "@/api/erp/voucherDesign"; //获取物料档案动态表单
import { list as listInventory, save, deleteInventory } from "@/api/inventory/inventory"; //获取物料数据
import { listTemplate } from "@/api/inventory/barcode";
import { warehouseModal, inventoryModal, inventoryAfterModal, unitDropDownSearch, unitsDropDownSearch, warehouseGoodsModal, officeModal } from "@/components/PopUpLayer";//各种搜索选择弹窗
import { getPhonetic } from "@/api/common/py";
import { Controlwidth } from "@/utils/antTableComponents";
import importAndExport from "@/components/ImportAndExport/index"
import QRCode from "qrcodejs2";
import html2canvas from "@/utils/html2canvas"
import VueQr from 'vue-qr'
import moment from "moment";
//获取汉子首字母
import PY from "@/utils/pinyinUtil/pinyin"

import dynamicForm from "./dynamic/dynamicFrom";
import barcodeUtil from '@/views/inventory/barcode/barcodeUtil';
import { getLodop } from "@/utils/tool/LodopFun";
var LODOP;
let treeData = [];

export default {
    mixins: [table],
    components: {
        VueQr,
        cardWrapper,
        dynamicForm,
        warehouseModal,
        inventoryModal,
        inventoryAfterModal,
        unitDropDownSearch,
        unitsDropDownSearch,
        warehouseGoodsModal,
        officeModal,
        importAndExport,
        barcodeUtil
    },
    data () {
        const columns = [
            {
                title: "物料编码",
                dataIndex: "inventoryCode",
                key: "inventoryCode",
                width: 120,
                scopedSlots: {
                    filterDropdown: 'filterDropdownCode',
                    filterIcon: 'filterIconCode',
                },
            },
            {
                title: "物料名称",
                dataIndex: "inventoryName",
                key: "inventoryName",
                width: 120,
                scopedSlots: {
                    filterDropdown: 'filterDropdown',
                    filterIcon: 'filterIcon',
                },
            },
            {
                title: "规格型号", dataIndex: "inventorySpecification", key: "inventorySpecification", width: 110,
                scopedSlots: {
                    filterDropdown: 'filterDropdownG',
                    filterIcon: 'filterIcon',
                }
            },
            { title: "物料分类", dataIndex: "inventoryClassName", key: "inventoryClassName", width: 80, ellipsis: true },
            { title: "存货分类", dataIndex: "inventoryCategoryName", key: "inventoryCategoryName", width: 80, ellipsis: true },
            // { title: "计价方式", dataIndex: "pricingMethod", key: "pricingMethod", width: 80 },
            { title: "计量单位", dataIndex: "unitName", key: "unitName", scopedSlots: { customRender: "unitName" }, width: 80 },
            { title: "计量单位组", dataIndex: "unitGroupName", key: "unitGroupName", width: 80 },
            { title: "主计量单位", dataIndex: "mainUnitName", key: "mainUnitName", width: 80 },
            { title: "物料属性", dataIndex: "inventoryAttribute", key: "inventoryAttribute", width: 240, ellipsis: true },
        ];

        //
        const unitGroupColumns = [
            {
                title: "序号",
                dataIndex: "key",
                key: "key",
                width: 60,
                scopedSlots: { customRender: "indexNumber" }
            },
            // { title: "计量单位组", dataIndex: "unitGroupId" },
            { title: "计量单位", dataIndex: "name", key: "name" },
            { title: "主计量", dataIndex: "isMainUnit", scopedSlots: { customRender: "isMainUnit" } },
            { title: "换算类型", dataIndex: "convertType", scopedSlots: { customRender: "convertType" } },
            { title: "换算率", dataIndex: "changeRate", scopedSlots: { customRender: "changeRate" } },
            { title: "换算说明", dataIndex: "rateDescription" },
        ]

        return {
            openPrint: false,//是否点击打印
            editModal: false,
            editItem: {},
            treeData,
            treeDataMap: new Map(),
            columns,
            unitGroupColumns,
            editData: [],
            count: 0,
            form: '',
            expandedKeys: [],
            autoExpandParent: true,
            searchName: "", //tree搜索名称
            treeLeftDataRows: '',//左侧树选中的数据
            tableData: [], //右侧表数据
            selectedRowKeys: [],//checkbox选中的值
            isRouterAlive: true,//治不渲染用的
            pagination: {
                defaultPageSize: 20,
                current: 1,
                pageSize: 20,
                size: 'small',
                total: 0,
                showTotal: (total) => {
                    return (
                        <div>
                            共 {total} 条数据，每页
                            <a-input-number
                                class="page-input"
                                value={this.pagination.pageSize}
                                min={1}
                                max={500}
                                onPressEnter={(e) => this.changePageSize(e)}
                            />
                            条
                        </div>
                    );
                },
                showQuickJumper: true,
                showLessItems: true,
                onChange: (e) => {
                    this.pagination.current = e;
                    this.getData();
                }
            },
            customClick: (record, index) => ({
                on: {
                    dblclick: (event) => {
                        event.preventDefault();
                        this.selectedData = [];
                        this.selectedData.push(record);
                        this.activeKey = '1';
                        this.edit();
                    },
                },
            }),
            postData: {
                current: 1,
                size: 20,
                classId: null,
            },
            replaceFields: {
                title: "showTitle",
            },
            // 图片上传参数
            headersData: {
                "Access-Token": Vue.ls.get(ACCESS_TOKEN),
            },
            previewVisible: false,
            previewImage: "",
            fileList: [],

            fromRequestData: {
                //单据请求参数
                source: "Inventory",
            },
            frombackData: {}, //请求返回的动态from结构
            fromCommonData: [], //常用信息
            fromBasicData: [], //基本信息
            fromYesNoData: [],//基本信息（是否复选）
            fromPictureData: [], //图片
            fromInventoryData: [], //库存信息
            fromControlData: [], //控制
            fromBarCodeData: [], //二维码
            fromBatchData: [], //批号管理
            fromCommodityData: [],//商品属性
            fromWeightData: [],//重量、尺寸
            commodityData: [{ key: '', value: '' }],//商品属性json值

            selectIds: '',//表格头部checkbox勾选的id组
            selectedData: [],//表格头部checkbox勾选的json组

            moreOrLittle: 0,//选择的是多计量1还是单剂量0
            changeDw: ['purUnit', 'costUnit', 'inUnit', 'saleUnit', 'proUnit', 'retailUnit', 'subUnitByReport'],//subUnitByReport
            changeDwName: ['purUnitName', 'costUnitName', 'inUnitName', 'saleUnitName', 'proUnitName', 'retailUnitName', 'subUnitByReportName'],//subUnitByReport
            locationName: '',   //货位
            locationId: '',     //货位Id

            detailsTableData: [],//多计量下面参数

            archivesId: null,    //物料id
            copySelectedData: [],    //复制的值
            copyBtn: false,          //复制按钮（修改的时候才可以复制）
            activeKey: '1',
            afterCode: '',
            tableSearchCode: '',//table上面搜索条件
            tableSearchName: '',
            inventorySpecificationSearch: '',
            numberReg: /^-?\d+$/,
            numberAndWordReg: /^-?\w+$/,
            checkSql: /select|update|delete|exec|count|'|"|=|;|>|<|%/i,
            classId: null,//分类id
            isShowFromYesNoData: true,
            dict: JSON.parse(localStorage.getItem('dict')),//字典
            templateList: null,                             //物料档案 模板
        };
    },
    beforeCreate () {
        this.form = this.$form.createForm(this, { name: "advanced_search" })
    },
    watch: {
        // frombackData.pyCode(val){

        // },
    },
    created () {
        this.calssList();//获取左侧树形数据
        this.getData();//获取表格数据
        this.getFromDataSource();
    },
    activated () {
        this.calssList();//获取左侧树形数据
        this.ListInInventoryTemplate();
    },
    updated () {
        Controlwidth("archives_setting_tb", 80)
    },
    computed: {
        ...mapState({
            userInfo: state => state.user.info,
            permissions: state => state.user.permissions,
        }),
    },
    methods: {
        moment,
        //获取物料打印模板
        ListInInventoryTemplate () {
            let params = { applicableObject: "InInventory", isDefault: true };
            listTemplate(params).then(res => {
                if (res.code == 200) {
                    res.data && res.data.forEach(item => item.key = item.id);
                    this.templateList = res.data;
                } else {
                    // this.$message.warning(res.message);
                }
            })
        },
        reload () {
            this.isRouterAlive = false;
            this.$nextTick(function () {
                this.isRouterAlive = true;
            });
        },
        //刷新
        syncFun () {
            this.calssList();//获取左侧树形数据
            this.ListInInventoryTemplate();
            this.getData();//获取表格数据
            this.getFromDataSource();
        },
        //改变分页大小
        changePageSize (e) {
            const value = e.target.value;
            let size = Number.parseInt(value);
            if (!size) {
                size = 20;
            }
            if (size > 500) {
                size = 500;
            }
            const { pagination } = this;

            Object.assign(this.pagination, {
                current: 1,
                pageSize: size
            });
            this.getData();//获取表格数据
        },
        //换算率事件
        changeRate () {
            let mainunitNamt = '';
            for (let i = 0; i < this.detailsTableData.length; i++) {
                if (this.detailsTableData[i].isMainUnit) {
                    mainunitNamt = this.detailsTableData[i].name
                }

                if (!this.detailsTableData[i].isMainUnit) {
                    let data = this.detailsTableData[i];
                    data.isMainUnit = false;
                    if (data.name && data.changeRate && mainunitNamt) {
                        data.rateDescription = "1" + mainunitNamt + "=" + data.changeRate + data.name;
                    }
                    this.$set(this.detailsTableData, i, data);
                }
            }
        },
        formatVal (val) {
            //改变下拉数据结构
            let backJson = [];
            if (val && val != '' && val != null) {
                for (let i = 0; i < val.length; i++) {
                    backJson.push({
                        'id': val[i].id,
                        'name': val[i].name
                    })
                }
            }
            return backJson;
        },
        // 互斥 方法
        inventoryAttributMutexe (item) {
            console.log("互斥方法", item);
            if (!item) return;
            let { fromYesNoData } = this;
            console.log("物料属性", fromYesNoData);
            if (item.code == 'isInventedKey') {
                fromYesNoData.forEach(i => {
                    if (i.code != 'isInventedKey') {
                        i.onLocalNoEdit = item.valueName;
                    }
                })
            } else {
                let isTrue = fromYesNoData.some(i => i.code != 'isInventedKey' && (i.valueName));
                console.log("isTrue", isTrue)
                fromYesNoData.forEach(i => {
                    if (i.code == 'isInventedKey') {
                        i.onLocalNoEdit = !!isTrue;
                    }
                })
            }
            this.isShowFromYesNoData = false;
            this.$nextTick(function () {
                this.isShowFromYesNoData = true;
            });
        },
        onSelectChange (keys, row) {
            const ids = new Array();
            row.forEach(function (val) {
                ids.push(val.id);
            });
            this.selectIds = ids;
            this.selectedRowKeys = keys;
            this.selectedData = row;
        },
        jlselect (code, val) {
            //下拉选择处理事件
            for (let i = 0; i < this.frombackData.length; i++) {
                if (this.frombackData[i].code == code) {
                    this.$set(this.frombackData[i], 'valueId', val)
                }
            }
        },
        setValue (val) {
            //设置弹出框选中的值
            const { frombackData } = this;

            //物料分类(如果选择物料分类，物料编码自动填入)
            if (val.code == 'inventoryClassId') {
                for (let i = 0; i < frombackData.length; i++) {
                    if (frombackData[i].code == val.code) {
                        //物料分类
                        this.$set(frombackData[i], 'valueId', val.id)
                        this.$set(frombackData[i], 'valueName', val.name)
                    }
                    if (frombackData[i].code == 'inventoryCode') {
                        //物料编码
                        this.$set(frombackData[i], 'valueName', val.classCode)
                    }
                }
            }
            //存货分类
            if (val.code == 'inventoryCategoryId') {
                for (let i = 0; i < frombackData.length; i++) {
                    if (frombackData[i].code == val.code) {
                        this.$set(frombackData[i], 'valueId', val.id)
                        this.$set(frombackData[i], 'valueName', val.name)
                    }
                }
            }


            //默认仓库
            if (val.code == 'warehouseId') {
                for (let i = 0; i < frombackData.length; i++) {
                    if (frombackData[i].code == val.code) {
                        this.$set(frombackData[i], 'valueId', val.id)
                        this.$set(frombackData[i], 'valueName', val.name)
                        //选择的货位id
                        this.locationId = val.id;

                        this.$refs.locationRef.getData(val.id);
                    }
                }
            }

            //默认货位
            if (val.code == 'locationId') {
                for (let i = 0; i < frombackData.length; i++) {
                    if (frombackData[i].code == val.code) {
                        //物料分类
                        this.$set(frombackData[i], 'valueId', val.id)
                        this.$set(frombackData[i], 'valueName', val.name)
                    }
                }
            }

            //营销机构
            if (val.code == 'agenciesId') {
                for (let i = 0; i < frombackData.length; i++) {
                    if (frombackData[i].code == val.code) {
                        //营销机构
                        this.$set(frombackData[i], 'valueId', val.id)
                        this.$set(frombackData[i], 'valueName', val.name)
                    }
                }
            }

            Object.assign(this, frombackData)
        },
        selectModalShow (code) {
            if (code == 'inventoryClassId') {
                //物料分类
                this.$nextTick(() => {
                    this.$refs.invenRef.showModal(code);
                    this.$refs.invenRef.getData();
                })
            } else if (code == 'locationId') {
                //默认货位
                this.$nextTick(() => {
                    this.$refs.locationRef.showModal(code);
                })
            } else if (code == 'warehouseId') {
                //默认仓库
                this.$nextTick(() => {
                    this.$refs.warehouseRef.showModal(code);
                })
            } else if (code == 'agenciesId') {
                //所属营销机构
                this.$nextTick(() => {
                    this.$refs.agenciesRef.showModal(code);
                })
            } else if (code == 'inventoryCategoryId') {
                //存货分类
                this.$nextTick(() => {
                    this.$refs.invenAfterRef.showModal(code);
                    this.$refs.invenAfterRef.getData();
                })
            } else {
                this.$nextTick(() => {
                    this.$refs[`${code}`][0].showModal(code);
                })
            }
        },
        getFromDataSource () {
            //动态表单结构
            const { fromRequestData } = this;
            listDesign(fromRequestData).then((response) => {
                if (response.code === 200) {
                    const { data } = response;
                    this.frombackData = data;
                    this.changeToTabMap();
                }
            })
        },
        changeToTabMap () {
            //数据处理（用于弹窗）
            const frombackDataAll = this.frombackData;

            //过滤onOff 是否强制展示
            let frombackData = frombackDataAll.filter((item) => {
                return item.onOff == true;
            });

            for (let i = 0; i < frombackData.length; i++) {
                let d = frombackData[i];
                //valueId 就是要提交的值
                this.$set(d, 'valueName', '');
                this.$set(d, 'valueId', '');
                this.$set(d, 'isShow', true);
                //------------------------------------------------------配置默认值
                if (d.columnType == '是否') {
                    this.$set(d, 'valueName', false)
                }

                if (d.columnType == '字典') {
                    let map = new Map();
                    this.dict.forEach(item => {
                        map.set(item.dictCode, item)
                    });
                    if (d.code == 'dimensionUnit') {
                        //尺寸单位
                        let linear = map.get('linear_measure').dictDatas;
                        let array = [];
                        linear.forEach(l => {
                            array.push(l.dictValue);
                        });
                        d.val = array.join(',');
                    }
                    if (d.code == 'weightUnit') {
                        //重量单位
                        let weight = map.get('weight').dictDatas;
                        let array = [];
                        weight.forEach(l => {
                            array.push(l.dictValue);
                        });
                        d.val = array.join(',');
                    }
                }
                if (d.columnType == '下拉' || d.columnType == '字典') {
                    if (d.val && d.val != '' && d.val != null) {
                        let downjson = d.val.split(',');
                        let backdata = [];
                        for (let i = 0; i < downjson.length; i++) {
                            backdata.push(
                                { 'id': downjson[i], 'name': downjson[i] }
                            )
                        }
                        d.val = backdata;

                        if (d.code == 'unitType') {
                            this.$set(d, 'valueId', d.val[0].name)
                            this.$set(d, 'valueName', d.val[0].name)
                        }
                    }
                }
                if (d.code == 'mainUnit') {
                    //主计量默认不可写
                    this.$set(d, 'onEdit', false)
                }
                // if (d.code == 'locationId') {
                //     //默认货位默认不可选
                //     this.$set(d, 'onEdit', false)
                // }
                //----------------------------------------------------------配置默认值

                //是单计量还是多计量
                d.unitType == '多计量' ? this.moreOrLittle == 1 : this.moreOrLittle == 0;
                //默认单计量（多计量组不显示）
                if (this.moreOrLittle == 1) {
                    d.code == 'unitId' ? this.$set(d, 'isShow', false) : '';
                    d.code == 'unitGroupId' || d.code == 'mainUnit' ? this.$set(d, 'isShow', true) : '';
                    for (let j = 0; j < frombackData.length; j++) {
                        for (let k = 0; k < this.changeDw.length; k++) {
                            if (frombackData[j].code == this.changeDw[k]) {
                                this.$set(frombackData[j], 'onEdit', true);
                            }
                        }
                    }
                } else {
                    d.code == 'unitId' ? this.$set(d, 'isShow', true) : '';
                    d.code == 'unitGroupId' || d.code == 'mainUnit' ? this.$set(d, 'isShow', false) : '';
                    //单计量时默认不可选的项
                    for (let j = 0; j < frombackData.length; j++) {
                        for (let k = 0; k < this.changeDw.length; k++) {
                            if (frombackData[j].code == this.changeDw[k]) {
                                this.$set(frombackData[j], 'onEdit', false);
                            }
                        }
                    }
                }

                //特殊处理的加slot(计量方式)
                if (d.code == 'unitType') {
                    this.$set(d, 'slot', d.code);
                }
                if (d.columnType == '日期') {
                    this.$set(d, 'slot', d.code);
                }
            }

            this.fromCommonData = frombackData.filter((item) => {
                return item.dataTab == "常用信息";
            });

            this.fromBasicData = frombackData.filter((item) => {
                return item.dataTab == "基本信息" && item.columnType != "是否复选";
            });

            this.fromYesNoData = frombackData.filter((item) => {
                return item.columnType == "是否";
            });

            this.fromPictureData = frombackData.filter((item) => {
                return item.dataTab == "图片";
            });
            this.fromInventoryData = frombackData.filter((item) => {
                return item.dataTab == "库存信息";
            });
            this.fromControlData = frombackData.filter((item) => {
                return item.dataTab == "控制";
            });
            this.fromBarCodeData = frombackData.filter((item) => {
                return item.dataTab == "二维码";
            });
            this.fromBatchData = frombackData.filter((item) => {
                return item.dataTab == "批号管理";
            });
            this.fromCommodityData = frombackData.filter((item) => {
                return item.dataTab == "商品属性";
            });
            this.fromWeightData = frombackData.filter((item) => {
                return item.dataTab == "重量/尺寸";
            });

            Object.assign(this.frombackData, frombackData)
        },
        handleCancel () {
            this.archivesId = null;
            this.editModal = false;
            this.fromBatchData = [];
            this.clearData();
        },
        handleCancelImg () {
            this.previewVisible = false;
        },
        async handlePreview (file) {
            if (!file.url && !file.preview) {
                file.preview = await getBase64(file.originFileObj);
            }
            this.previewImage = file.url || file.preview;
            this.previewVisible = true;
        },
        handleSubmit (type) {
            let { frombackData } = this;
            let datatype1 = []; //系统字段
            let datatype2 = []; //自定义字段


            //过滤onEdit==false 不返给后台
            let tempBackData = [];
            for (let j = 0; j < frombackData.length; j++) {
                for (let i = 0; i < this.changeDw.length; i++) {
                    if (frombackData[j].code == this.changeDw[i] || frombackData[j].code == 'mainUnit' || frombackData[j] == 'locationId') {
                        tempBackData.push(frombackData[j])
                    }
                }
                if (frombackData[j].onEdit == true || frombackData[j].code == 'inventoryClassId') {
                    tempBackData.push(frombackData[j])
                }
            }
            frombackData = tempBackData;

            datatype1 = frombackData.filter((item) => {
                return item.dataType == "1";
            });

            datatype2 = frombackData.filter((item) => {
                return item.dataType == "2";
            });

            //验证必填字段
            let unittype = '';
            let goRunSave = false;//是否有选择一条或者多条物料属性
            for (let n = 0; n < frombackData.length; n++) {
                if (frombackData[n].code == 'unitType' && frombackData[n].valueId == '多计量') {
                    unittype = 2;
                }
                if (unittype == 2) {
                    //多计量 去除，计量单位
                    if (frombackData[n].onFill && (frombackData[n].valueName == '' || frombackData[n].valueName == null) && frombackData[n].code != 'unitId') {
                        this.$message.warning(`${frombackData[n].name}必须填写！`);
                        return;
                    }
                } else {
                    //单计量 去除，计量单位组和主计量单位
                    if (frombackData[n].code != 'mainUnit' && frombackData[n].code != 'unitGroupId') {
                        if (frombackData[n].onFill && (frombackData[n].valueName == '' || frombackData[n].valueName == null)) {
                            this.$message.warning(`${frombackData[n].name}必须填写！`);
                            return;
                        }
                    }
                }


                //物料属性必须选择一项
                if (frombackData[n].columnType == '是否') {
                    if (frombackData[n].valueName) {
                        goRunSave = true;
                    }
                }
            }

            //物料属性必选判断
            if (!goRunSave) {
                this.$message.warning('物料属性必须选择一项');
                return;
            }
            // 校验 商品属性 是否有错误提示
            let inputWarnElements = document.getElementsByClassName("input-warn");
            if (inputWarnElements.length > 0) {
                this.$message.warning('请完善 商品属性');
                return;
            }
            let b = {}; //系统字段提交数据
            console.log(datatype1);
            datatype1.forEach((item) => {

                if (item.columnType == '下拉' || item.columnType == '搜索下拉' || item.columnType == '搜索选择') {
                    //用于页面展示 新增...Name字段
                    if (item.code.indexOf('Id') != '-1') {
                        let tempname = item.code.substring(0, item.code.length - 2) + 'Name';
                        this.$set(b, tempname, item.valueName);
                    }
                }
                if (item.columnType == '文本') {
                    if (item.code != 'mainUnit') {

                        //商品属性
                        if (item.dataTab == '商品属性') {
                            console.log(this.commodityData);
                            let attrData = this.commodityData.filter(res => { return res.key && res.value })
                            this.$set(b, item.code, JSON.stringify(attrData));
                        } else {
                            this.$set(b, item.code, item.valueName);
                        }
                        //物料编码
                        if (item.code == 'inventoryCode') {
                            this.$set(b, item.code, item.valueName + this.afterCode);
                        }
                    } else {
                        this.$set(b, item.code, item.valueId);
                        this.$set(b, 'mainUnitName', item.valueName);
                    }
                } else if (item.columnType == '整数' || item.columnType == '小数' || item.columnType == '是否') {
                    this.$set(b, item.code, item.valueName);
                } else {
                    if (item.valueId != '' && item.valueId != null) {

                        //给辅助计量单位赋值中文
                        this.changeDw.forEach(fuzhu => {
                            if (item.code == fuzhu) {
                                if (this.moreOrLittle == 1) {//多计量
                                    this.$set(b, item.code, item.valueId);

                                    // console.log(`卧槽${item.code}`, item.val.filter((e) => { return item.valueId == e.id }))
                                    this.$set(b, fuzhu + 'Name', item.val.filter((e) => { return item.valueId == e.id })[0].name);
                                } else {//单计量
                                    this.$set(b, item.code, item.valueId);
                                    this.$set(b, fuzhu + 'Name', item.valueName);
                                }

                            } else {
                                this.$set(b, item.code, item.valueId);
                            }

                        });

                    } else {
                        this.$set(b, item.code, item.valueName);
                    }
                }

            });

            // return;
            if (this.selectedData != '' && this.selectedData != []) {
                if (this.selectedData[0].id) {//这里标识修改
                    this.$set(b, 'id', this.selectedData[0].id);
                }
            }

            let c = {}; //自定义提交数据
            datatype2.forEach((item) => {
                // this.$set(c, item.code, item.valueId);
                this.$set(c, item.code, item.valueId || item.valueName);
            });
            let postData = b;
            this.$set(postData, "defineFields", JSON.stringify(c));
            // if (this.archivesId) {
            this.$set(postData, "id", this.archivesId);
            // }


            let saveDtoData = [];
            for (let i = 0; i < this.detailsTableData.length; i++) {
                //判断是保存还是修改
                if (!this.detailsTableData[i].unitId) {
                    //新增
                    let array = {
                        changeRate: this.detailsTableData[i].changeRate,
                        unitGroupId: this.detailsTableData[i].unitGroupId,
                        unitId: this.detailsTableData[i].id,
                    };
                    saveDtoData.push(array)
                } else {
                    //修改
                    let array = {
                        changeRate: this.detailsTableData[i].changeRate,
                        unitGroupId: this.detailsTableData[i].unitGroupId,
                        unitId: this.detailsTableData[i].unitId,
                        id: this.detailsTableData[i].id,
                        unitName: this.detailsTableData[i].name,
                    };
                    saveDtoData.push(array)
                }

            }

            //最终传给后台的数据
            let inInventorySaveDto = {
                inInventory: {},
                inInventoryUnitGroupDtos: []
            }

            if (postData.unitType == '多计量') {
                postData.unitName = null;
                postData.unitId = null;
            } else {
                postData.unitGroupId = null;
                postData.unitGroupName = null;
                postData.mainUnit = null;
                postData.mainUnitName = null;
            }

            if (this.checkSql.test(postData.inventoryCode)) {
                this.$message.warning('编码不能包含以下特殊字符\'、"、=、;、>、<、% 和 SQL关键字select|update|delete|exec|count');
                return false;
            }

            this.$set(inInventorySaveDto, "inInventory", postData);
            this.$set(inInventorySaveDto, "inInventoryUnitGroupDtos", saveDtoData);


            save(inInventorySaveDto).then((res) => {
                if (res.code == 200) {
                    this.archivesId = res.data;//物料id
                    this.$message.success("保存成功");

                    this.afterCode = '';



                    this.getData();
                    setTimeout(() => {
                        this.tableData.forEach((item, index) => {
                            if (item.id == res.data) {
                                this.selectedData = [item]
                            }
                        });
                        this.edit();

                        this.copyBtn = true;
                        if (type == 1) {
                            //保存并新增
                            this.clearData();
                            this.add();
                            this.copyBtn = false;
                        } else if (type == 2) {
                            //保存并复制
                            this.deleteId()
                            this.copyBtn = false;
                        }
                    }, 600)


                } else {
                    // this.$message.warning(res.message);
                }
            });
        },
        deleteId () {
            //复制新增 删除id
            this.archivesId = null;
            //复制的时候修改物料编码code

            for (let i = 0; i < this.frombackData.length; i++) {
                if (this.frombackData[i].code == 'inventoryCode') {
                    this.$set(this.frombackData[i], 'valueName', this.treeDataMap.get(this.selectedData[0].inventoryClassId))
                }
            }

            this.$message.success('复制成功', 2);
            // this.edit()
            this.copyBtn = false;


        },
        clearData () {
            //清空数据 刷新
            this.selectIds = [];
            this.selectedRowKeys = [];
            this.selectedData = [];
            this.archivesId = null;
            this.getData();
        },
        unitTypeChange (e) {
            //计量方式下拉事件
            let { frombackData } = this;
            let d = '多计量', s = '单计量';
            for (let i = 0; i < frombackData.length; i++) {
                if (e == d) {
                    this.moreOrLittle = 1;//1是多计量
                    //多计量
                    frombackData[i].code == 'unitId' ? this.$set(frombackData[i], 'isShow', false) : '';//单剂量
                    frombackData[i].code == 'unitGroupId' ? this.$set(frombackData[i], 'isShow', true) : '';//计量单位组
                    // frombackData[i].code == 'unitGroupId' ? this.$set(frombackData[i], 'valueName', '') : '';//计量单位组
                    frombackData[i].code == 'mainUnit' ? this.$set(frombackData[i], 'isShow', true) : '';//主计量单位
                    //多计量时可选
                    for (let j = 0; j < frombackData.length; j++) {
                        for (let k = 0; k < this.changeDw.length; k++) {
                            if (frombackData[j].code == this.changeDw[k]) {
                                this.$set(frombackData[j], 'onEdit', true);
                                this.$set(frombackData[j], 'valueName', "");
                            }
                        }
                    }

                }
                if (e == s) {
                    this.moreOrLittle = 0;//0是单计量
                    //单计量
                    frombackData[i].code == 'unitId' ? this.$set(frombackData[i], 'isShow', true) : '';
                    // frombackData[i].code == 'unitId' ? this.$set(frombackData[i], 'valueName', '') : '';
                    frombackData[i].code == 'unitGroupId' ? this.$set(frombackData[i], 'isShow', false) : '';
                    frombackData[i].code == 'mainUnit' ? this.$set(frombackData[i], 'isShow', false) : '';

                    //单计量时不可选的项
                    for (let j = 0; j < frombackData.length; j++) {
                        for (let k = 0; k < this.changeDw.length; k++) {
                            if (frombackData[j].code == this.changeDw[k]) {
                                this.$set(frombackData[j], 'onEdit', false);
                                this.$set(frombackData[j], 'valueName', "");
                            }
                        }
                    }
                }
            }
            Object.assign(this.frombackData, frombackData);


        },
        handleChange ({ fileList }) {
            this.fileList = fileList;
        },
        //tree 搜索
        treeSearch () {
            const value = this.searchName;
            const keys = [];
            const treeData = searchInTreeData(
                keys,
                this.treeData,
                "title",
                value
            );
            if (keys.length < 1) {
                this.expandedKeys = [...groupMap.keys()];
                this.autoExpandParent = false;
            } else {
                this.expandedKeys = keys;
                this.autoExpandParent = true;
            }
        },
        calssList () {
            //获取树形菜单数据
            list().then((res) => {
                if (res.code == 200) {
                    const childrenNav = [];
                    classPageListToTree(res.data, childrenNav, 0);
                    let childrenData = this.getTreeData(childrenNav);
                    console.log('childrenData:', childrenData);

                    this.treeDataMapFunction(childrenData);
                    this.treeData = [
                        {
                            title: "物料分类",
                            showTitle: "物料分类",
                            key: "-1",
                            children: childrenData,
                        },
                    ];
                }
            });
        },
        treeDataMapFunction (data) {
            //tree Map 递归遍历数组
            data.forEach(tree => {
                this.treeDataMap.set(tree.id, tree.classCode);
                if (tree.children && tree.children.length > 0) {
                    this.treeDataMapFunction(tree.children)
                }
            });

        },
        getData (classCode) {
            // if(this.treeLeftDataRows){
            //     classCode = this.treeLeftDataRows.node.dataRef.classCode
            // }
            //获取右侧表数据
            let params = {
                current: this.pagination.current,
                size: this.pagination.pageSize,
                inventoryClassCode: classCode ? classCode : this.treeLeftDataRows ? this.treeLeftDataRows.node.dataRef.classCode : null,
            };

            if (this.tableSearchCode) {
                params.inventoryCode = this.tableSearchCode;
            }
            if (this.tableSearchName) {
                params.inventoryName = this.tableSearchName;
            }

            if (this.inventorySpecificationSearch) {
                params.inventorySpecification = this.inventorySpecificationSearch;
            }
            // alert(params.inventoryCode);
            listInventory(params).then((res) => {
                if (res.code == 200) {
                    this.$nextTick(() => {
                        this.tableData = res.data.records;
                        this.tableData.forEach(item => {
                            item.key = item.id;
                            let attribute = [];
                            if (item.defineFields && item.defineFields != "{}") {
                                let data = JSON.parse(item.defineFields);
                                for (const key in data) {
                                    item[key] = data[key];
                                }
                            }
                            if (item.isPurchasing) {
                                attribute.push('允许外购');
                            }
                            if (item.isForSale) {
                                attribute.push('允许销售');
                            }
                            if (item.isMadeSelf) {
                                attribute.push('允许自制');
                            }
                            if (item.isMaterial) {
                                attribute.push('允许生产耗用');
                            }
                            if (item.isLaborCost) {
                                attribute.push('允许劳务费用');
                            }
                            if (item.isSuite) {
                                attribute.push('允许成套件');
                            }
                            if (item.isMadeRequest) {
                                attribute.push('允许委外');
                            }
                            if (item.isInventedKey) {
                                attribute.push('允许虚拟件');
                            }
                            item.inventoryAttribute = attribute.join('，')
                        });

                        Object.assign(this.pagination, {
                            total: res.data.total,
                        });
                    })

                } else {
                    // this.$message.warning(res.message);
                }

            });
        },
        page (p) {
            this.getData();

            // this.frombackData.forEach(el => {
            //     if (el.code == 'unitGroupId') {
            //         this.$set(el, 'valueId', '')
            //         this.$set(el, 'valueName', '')
            //     }
            // });

            let nowindex = null;
            this.tableData.forEach((item, index) => {
                if (item.id == this.archivesId) {
                    nowindex = index;
                }
            });

            this.selectedData = [];

            if (p == 1) {
                //上一页
                let prev = nowindex - 1;
                if (prev < 0) {
                    this.$message.destroy();
                    this.$message.warning('已经是首页');
                    return;
                } else {
                    let b = this.tableData[prev];
                    this.selectedData = [b];
                }
            }
            if (p == 2) {
                //下一页
                let next = nowindex + 1;
                if (next == this.tableData.length) {
                    this.$message.destroy();
                    this.$message.warning('已经是末页');
                    return;
                } else {
                    let b = this.tableData[next];
                    this.selectedData = [b];
                }
            }
            if (p == 3) {
                //首页
                if (nowindex == 0) {
                    this.$message.destroy();
                    this.$message.warning('已经是首页');
                    return;
                } else {
                    let b = this.tableData[0];
                    this.selectedData = [b];
                }
            }
            if (p == 4) {
                //尾页
                if (nowindex == this.tableData.length - 1) {
                    this.$message.destroy();
                    this.$message.warning('已经是尾页');
                    return;
                } else {
                    let b = this.tableData[this.tableData.length - 1];
                    this.selectedData = [b];
                }
            }
            this.activeKey = '1';
            this.edit();
        },
        getTreeData (data) {
            //递归添加显示的tree showTitle
            for (let i = 0; i < data.length; i++) {
                let element = data[i];
                this.$set(
                    element,
                    "showTitle",
                    `(${element.classCode}) ${element.title}`
                );
                if (element.children) {
                    this.getTreeData(element.children);
                }
            }
            return data;
        },
        add () {
            this.copyBtn = false;
            this.activeKey = '1';
            this.commodityData = [{ key: '', value: '' }];
            const { treeLeftDataRows } = this;
            if (treeLeftDataRows) {
                if (treeLeftDataRows.node.dataRef.key == '-1') {
                    this.$message.error('不是最后一级')
                    return;
                } else if (treeLeftDataRows.node.dataRef.children) {
                    this.$message.error('不是最后一级')
                    return;
                } else {
                    this.frombackData.forEach(element => {
                        if (element.code != 'inventoryClassId' && element.code != 'inventoryCode') {
                            element.valueName = '';
                            element.valueId = '';
                        } else {
                            if (this.treeLeftDataRows) {
                                if (element.code == 'inventoryCode') {
                                    this.$set(element, 'valueName', this.treeLeftDataRows.selectedNodes[0].data.props.classCode)
                                }
                            }
                        }



                        if (element.columnType == '是否') {
                            element.valueName = false;
                        }
                        if (element.code == 'unitType') {
                            this.$set(element, 'valueId', element.val[0].name)
                            this.$set(element, 'valueName', element.val[0].name)
                        }
                        this.moreOrLittle = 0;//默认计量单位组不能点击
                    });

                    this.afterCode = '';
                    this.editModal = true;
                    this.selectIds = [];
                    this.selectedRowKeys = [];
                    this.selectedData = [];
                }
            } else {
                this.frombackData.forEach(element => {

                    this.$set(element, 'valueName', '');
                    this.$set(element, 'valueId', '');

                    if (element.columnType == '是否') {
                        element.valueName = false;
                    }
                    if (element.code == 'unitType') {
                        this.$set(element, 'valueId', element.val[0].name)
                        this.$set(element, 'valueName', element.val[0].name)
                    }
                    this.moreOrLittle = 0;//默认计量单位组不能点击


                });
                this.afterCode = '';
                this.editModal = true;
                this.selectIds = [];
                this.selectedRowKeys = [];
                this.selectedData = [];
            }

            for (const key in this.frombackData) {
                this.frombackData[key].code == 'unitId' ? this.$set(this.frombackData[key], 'isShow', true) : '';//单计量
                this.frombackData[key].code == 'unitGroupId' ? this.$set(this.frombackData[key], 'isShow', false) : '';//计量单位组
                this.frombackData[key].code == 'mainUnit' ? this.$set(this.frombackData[key], 'isShow', false) : '';//主计量单位

                //清空辅助单位
                for (let k = 0; k < this.changeDw.length; k++) {
                    if (this.frombackData[key].code == this.changeDw[k]) {
                        this.$set(this.frombackData[key], 'onEdit', false);
                        this.$set(this.frombackData[key], 'val', '');
                        this.$set(this.frombackData[key], 'valueName', '');
                        this.$set(this.frombackData[key], 'valueId', '');
                    }
                }
            }
        },
        edit () {
            //修改选中数据
            //只能选中一个
            this.detailsTableData = [];
            this.activeKey = '1';
            this.copyBtn = true;

            let { frombackData, selectedData } = this;

            console.log('修改的数据', selectedData);
            if (selectedData.length == 0) {
                this.$message.warning('请选择一条数据');
                return false;
            } else if (selectedData.length > 1) {
                this.$message.warning('只能选择一条数据');
                return false;
            } else {
                this.archivesId = selectedData[0].id;
                if (this.selectedData[0].unitType == '多计量') {
                    //多计量的时候获取计量单位
                    this.getGroupIds(selectedData[0].id);
                }
                for (const key in frombackData) {
                    if (this.selectedData[0].unitType == '单计量') {
                        this.moreOrLittle = 0;
                        frombackData[key].code == 'unitId' ? this.$set(frombackData[key], 'isShow', true) : '';//单剂量
                        frombackData[key].code == 'unitGroupId' ? this.$set(frombackData[key], 'isShow', false) : '';//计量单位组
                        frombackData[key].code == 'mainUnit' ? this.$set(frombackData[key], 'isShow', false) : '';//主计量单位

                        //单计量的辅助单位不可改
                        for (let j = 0; j < frombackData.length; j++) {
                            for (let k = 0; k < this.changeDw.length; k++) {
                                if (frombackData[j].code == this.changeDw[k]) {
                                    this.$set(frombackData[j], 'onEdit', false);
                                }
                            }
                        }

                    } else {
                        this.moreOrLittle = 1;
                        frombackData[key].code == 'unitId' ? this.$set(frombackData[key], 'isShow', false) : '';//单剂量
                        frombackData[key].code == 'unitGroupId' ? this.$set(frombackData[key], 'isShow', true) : '';//计量单位组
                        frombackData[key].code == 'mainUnit' ? this.$set(frombackData[key], 'isShow', true) : '';//主计量单位
                        //多计量的辅助单位可改
                        for (let j = 0; j < frombackData.length; j++) {
                            for (let k = 0; k < this.changeDw.length; k++) {
                                if (frombackData[j].code == this.changeDw[k]) {
                                    this.$set(frombackData[j], 'onEdit', true);
                                }
                            }
                        }
                    }

                    if (frombackData[key].code == 'pricingMethod') {//计价方式
                        this.$set(frombackData[key], 'valueName', selectedData[0][frombackData[key].code])
                    } else {
                        if (frombackData[key].code == 'commodityAttribute') {
                            if (selectedData[0][frombackData[key].code] != null) {
                                this.commodityData = JSON.parse(selectedData[0][frombackData[key].code])
                            } else {
                                this.commodityData = [{
                                    key: '',
                                    value: '',
                                }];
                            }
                        } else {
                            this.$set(frombackData[key], 'valueId',)
                            this.$set(frombackData[key], 'valueName', selectedData[0][frombackData[key].code])
                        }

                    }

                    if (frombackData[key].columnType == '下拉' || frombackData[key].columnType == '搜索下拉' || frombackData[key].columnType == '搜索选择') {
                        //修改时展示...Name字段
                        if (frombackData[key].code.indexOf('Id') != '-1') {
                            let tempname = frombackData[key].code.substring(0, frombackData[key].code.length - 2) + 'Name';
                            this.$set(frombackData[key], 'valueId', selectedData[0][frombackData[key].code])
                            this.$set(frombackData[key], 'valueName', selectedData[0][tempname])
                        } else {
                            this.$set(frombackData[key], 'valueId', selectedData[0][frombackData[key].code])
                            this.$set(frombackData[key], 'valueName', selectedData[0][frombackData[key].code])
                        }
                    }

                }
                this.frombackData = Object.assign(this.frombackData, frombackData)

                this.editModal = true;
                //如果选择了多计量则获取下面的子计量
                if (selectedData[0].unitGroupId != null && selectedData[0].unitType == '多计量') {
                    this.$nextTick(() => {
                        this.$refs.unitGroupRef[0].getGrouplist(selectedData[0].unitGroupId, selectedData[0].unitGroupName)
                    })
                }

                if (selectedData[0].unitId != null && selectedData[0].unitType == '单计量') {
                    this.$nextTick(() => {
                        this.$refs.unitRef[0].getList(selectedData[0].unitId);
                    })
                }



            }
        },
        getGroupIds (id) {
            //多计量的时候获取计量单位
            let request = {
                inInventoryId: id,
            }
            groupList(request).then((res) => {
                if (res.code == 200) {
                    for (let i = 0; i < res.data.length; i++) {
                        this.$set(res.data[i], 'name', res.data[i].unitName);
                    }
                    this.detailsTableData = res.data
                }
            });
        },
        remove () {
            //删除
            var _this = this;
            if (this.selectedRowKeys.length == 0) {
                this.$message.warning('请至少选择一条数据');
                return false;
            } else {
                this.$confirm({
                    title: "确认",
                    content: (
                        <span>
                            您确定要{<span style="color:red;">删除</span>}该记录吗？
                        </span>
                    ),
                    onOk () {
                        let ids = [];
                        for (let i = 0; i < _this.selectedData.length; i++) {
                            ids.push(_this.selectedData[i].id)
                        }
                        deleteInventory(ids).then((res) => {
                            if (res.code == 200) {
                                _this.$message.success("删除成功");
                                _this.clearData();
                            } else {
                                // _this.$message.warning(res.message);
                            }
                        });
                    },
                    onCancel () { },
                });
            }

        },
        treeSelect (key, rows) {
            //左侧树形菜单
            const { frombackData } = this;
            this.pagination.current = 1;
            console.log(rows.node.dataRef);
            this.classId = rows.node.dataRef.id;
            this.getData(rows.node.dataRef.classCode)
            if (rows.selected) {
                this.treeLeftDataRows = rows;
                //如果选择的树是顶级不做处理
                if (rows.node.dataRef.key == '-1' || rows.node.dataRef.children) {
                    for (let i = 0; i < frombackData.length; i++) {
                        //如果选择所属类别，物料编码自动填入
                        if (frombackData[i].code == 'inventoryClassId') {
                            this.$set(frombackData[i], 'valueId', '')
                            this.$set(frombackData[i], 'valueName', '')
                        }
                        if (frombackData[i].code == 'inventoryCode') {
                            this.$set(frombackData[i], 'valueName', '')
                        }
                    }
                    Object.assign(this.frombackData, frombackData)
                } else {
                    for (let i = 0; i < frombackData.length; i++) {
                        //如果选择所属类别，物料编码自动填入
                        if (frombackData[i].code == 'inventoryClassId') {
                            this.$set(frombackData[i], 'valueId', rows.node.dataRef.id)
                            this.$set(frombackData[i], 'valueName', rows.node.dataRef.title)
                        }
                        if (frombackData[i].code == 'inventoryCode') {
                            this.$set(frombackData[i], 'valueName', rows.node.dataRef.classCode)
                        }
                    }
                    Object.assign(this.frombackData, frombackData)
                }
            } else {
                this.treeLeftDataRows = null;
            }

        },
        onChangeTimeA (date, dateString) {
            //时间处理string
            const { frombackData } = this;
            for (let i = 0; i < frombackData.length; i++) {
                if (frombackData[i].code == 'startCountTime') {
                    frombackData[i].valueId = dateString
                }
            }
            Object.assign(this.frombackData, frombackData)
        },
        onChangeTimeB (date, dateString) {
            //时间处理string
            const { frombackData } = this;
            for (let i = 0; i < frombackData.length; i++) {
                if (frombackData[i].code == 'lastCountTime') {
                    frombackData[i].valueId = dateString
                }
            }
            Object.assign(this.frombackData, frombackData)
        },
        okUnit (data) {
            //计量单位选择
            console.log('计量单位选择', data);
            const { frombackData } = this;
            for (let i = 0; i < frombackData.length; i++) {
                if (frombackData[i].code == data.propertyName) {
                    this.$set(frombackData[i], 'valueId', data.id)
                    this.$set(frombackData[i], 'valueName', data.name)
                }
                if (this.moreOrLittle == 0) {
                    //单剂量
                    // for (let j = 0; j < frombackData.length; j++) {
                    for (let k = 0; k < this.changeDw.length; k++) {
                        if (frombackData[i].code == this.changeDw[k]) {
                            this.$set(frombackData[i], 'val', data.val);
                            this.$set(frombackData[i], 'valueName', data.name);
                            this.$set(frombackData[i], 'valueId', data.id);
                        }
                    }
                    // }
                } else {
                    //多计量
                    this.detailsTableData = data.detailsData;
                    // for (let j = 0; j < frombackData.length; j++) {
                    for (let k = 0; k < this.changeDw.length; k++) {//给多个常用单位赋值
                        if (frombackData[i].code == this.changeDw[k]) {

                            let valData = data.val.filter(item => item.id != data.mainUnitId);//排除主计量
                            // let valData = data.val;
                            this.$set(frombackData[i], 'val', valData);


                            if (valData) {
                                let isHave = valData.some(f => f.id == frombackData[i].valueId);
                                if (!isHave) {//如果不匹配id，证明是切换了多计量组，在重新置入辅计量值
                                    this.$set(frombackData[i], 'valueName', valData[0].name);
                                    this.$set(frombackData[i], 'valueId', valData[0].id);
                                }
                            }
                        }
                    }
                    //主计量单位注入值
                    if (frombackData[i].code == 'mainUnit') {
                        this.$set(frombackData[i], 'valueId', data.mainUnitId);
                        this.$set(frombackData[i], 'valueName', data.mainUnitName);
                    }
                    // }
                }
            }
            Object.assign(this.frombackData, frombackData)
        },
        callback (key) {
            //tabs 切换事件
            this.activeKey = key;
            const { frombackData } = this;
            if (key == 4) {
                for (let i = 0; i < frombackData.length; i++) {
                    if (frombackData[i].code == 'warehouseId' && frombackData[i].valueId != '') {
                        this.$nextTick(() => {
                            this.$refs.locationRef.getData(frombackData[i].valueId);
                        })
                    }
                }
            }
        },
        inventoryChange (val) {
            //物料名称更改
            let pycode = '';
            this.frombackData.forEach(element => {
                if (element.code == 'inventoryName') {
                    // pycode = PY.firstPY(element.valueName)
                    getPhonetic({ keyword: element.valueName }).then(response => {
                        if (response.code === 200) {
                            pycode = response.message;
                            this.frombackData.forEach(item => {
                                if (item.code == 'pyCode') {
                                    this.$set(item, 'valueName', pycode)
                                }
                            });
                        }
                    })
                }
            });
        },
        importData () {
            //导入数据
            this.$refs.importRef.importFile();
        },
        exportData () {
            //导出数据
            this.$refs.importRef.exportCrmData(this.classId);
        },
        handleSearch (key, confirm, col) {
            //table搜索
            confirm();
            console.log(key, confirm, col)
            if (col == 'inventoryName') {
                this.tableSearchName = key[0];
                // this.inventorySpecificationSearch = null;
                // this.tableSearchCode = null;
            }

            if (col == 'inventoryCode') {
                this.tableSearchCode = key[0];
                // this.tableSearchName = null;
                // this.inventorySpecificationSearch = null;
            }

            if (col == 'inventorySpecification') {
                this.inventorySpecificationSearch = key[0];
                // this.tableSearchName = null;
                // this.tableSearchCode = null;
            }
            setTimeout(() => {
                this.getData();
            }, 300)
        },
        handleReset (clearFilters) {
            clearFilters();
            this.tableSearchCode = null;
            this.tableSearchName = null;
            this.inventorySpecificationSearch = null;
            this.getData()
        },
        addCommodityData () {
            //添加属性
            this.commodityData.push({
                key: '',
                value: '',
            })
        },
        deleteCommodityData (index) {
            this.commodityData.splice(index, 1); //删除下标为i的元素
            console.log(this.commodityData);
        },
        checkCommodityKey (e) {
            console.log("--属性名称 校验--", e)
            const value = e.target.value ? e.target.value : null;
            let isHasKey = this.commodityData.filter(f => f.key == value).length > 1;
            if (isHasKey) {
                this.$message.warning("属性名称不能重复");
                e.target.focus();
                e.target.className = "ant-input input-warn";
            } else {
                e.target.className = "ant-input";
            }
            console.log("--校验属性--", value);
        },
        //生成二维码 || 二维码
        creatQrCode () {
            this.$nextTick(() => {
                let aa = new QRCode(this.$refs.qrCodeUrl, {
                    text: selectedData[0].inventoryCode, // 需要转换为二维码的内容
                    width: 100,
                    height: 100,
                    colorDark: "#000000",
                    colorLight: "#ffffff",
                    correctLevel: QRCode.CorrectLevel.H
                });
            })
        },
        downImg () {
            html2canvas(document.querySelector("#barCodeBox")).then(canvas => {
                // document.body.appendChild(canvas)
                // document.getElementById('showBarCode').appendChild(canvas)
                this.downLoad(canvas.toDataURL("image/png"))
            });
        },
        downLoad (url) {
            var oA = document.createElement("a");
            oA.download = this.selectedData[0].inventoryName;// 设置下载的文件名，默认是'下载'
            oA.href = url;
            document.body.appendChild(oA);
            oA.click();
            oA.remove(); // 下载之后把创建的元素删除
        },



        qrCodePrint () {
            //打印预览Lodop
            console.log(this.selectedData);
            if (this.$refs.printPlugIn.CheckIsInstall()) {
                //是否下载打印插件
                return;
            }

            if (this.selectedData.length < 1) {
                this.$message.warning('请选择需要打印的数据');
                return;
            }

            LODOP = getLodop();
            LODOP.PRINT_INIT("");
            this.nihao(this.selectedData);
            LODOP.PREVIEW();
        },
        nihao (choiceData) {
            let { templateList } = this;
            let { companyName } = this.userInfo;
            let template = null;
            if (templateList.length > 0) {
                template = templateList[0].content;
                template = template.replace('LODOP.PRINT_INIT("");', "");
                template = template.replace(/"#{/g, "")
                template = template.replace(/}"/g, "")
                console.log(template);
            }
            let j = 0;
            for (let i = 0; i < choiceData.length; i++) {
                let data = choiceData[i];
                LODOP.NewPage();
                if (template) {
                    eval(template + "console.log(data.inventoryCode);");

                } else {
                    // LODOP.PRINT_INIT("");
                    // LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE",1);
                    LODOP.ADD_PRINT_TABLE(23, -2, 379, "70.38mm", "<table  border=\"1\"  cellpadding=\"10\" style=\"font-family:幼圆;font-weight:bold;text-align:center;margin:0 auto;font-weight:bold;color:#000;border:1px solid #000;border-collapse: collapse;\">\r\n                    <tr>\r\n                        <td style=\"width:320px\" colspan=\"3\">" + this.userInfo.companyName + "</td>\r\n                    </tr>\r\n                    <tr>\r\n                        <td>物料编码</td>\r\n                        <td style=\"width:220px\"colspan=\"2\"></td>\r\n                    </tr>\r\n                    <tr>\r\n                        <td>物料名称</td>\r\n                        <td colspan=\"2\"></td>\r\n                    </tr>\r\n                    <tr>\r\n                        <td>物料分类</td>\r\n                                                <td></td>\r\n                        <td rowspan=\"3\" ></td>\r\n                    </tr>\r\n                    <tr>\r\n                        <td>规格型号</td>\r\n                        <td></td>\r\n                    </tr>\r\n                    <tr>\r\n                        <td>计量单位</td>\r\n                        <td></td>\r\n                    </tr>\r\n                </table>");
                    LODOP.ADD_PRINT_TEXT(72, 112, 218, 27, data.inventoryCode);//物料编码
                    LODOP.SET_PRINT_STYLEA(0, "FontName", "幼圆");
                    LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                    LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                    LODOP.ADD_PRINT_TEXT(110, 112, 217, 27, data.inventoryName);//物料名称
                    LODOP.SET_PRINT_STYLEA(0, "FontName", "幼圆");
                    LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                    LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                    LODOP.ADD_PRINT_TEXT(149, 112, 115, 27, data.inventoryClassName);//物料分类
                    LODOP.SET_PRINT_STYLEA(0, "FontName", "幼圆");

                    if (data.inventoryClassName.length >= 7) {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                    } else if (data.inventoryClassName.length >= 10) {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
                    } else {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                    }
                    LODOP.SET_PRINT_STYLEA(0, "OverFlow", 'hidden');
                    LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                    LODOP.ADD_PRINT_BARCODE(143, 241, 131, 120, "QRCode", data.inventoryCode);
                    LODOP.SET_PRINT_STYLEA(0, "QRCodeErrorLevel", "H");
                    LODOP.ADD_PRINT_TEXT(180, 112, 135, 27, data.inventorySpecification);//规格型号
                    LODOP.SET_PRINT_STYLEA(0, "FontName", "幼圆");

                    if (data.inventorySpecification.length >= 7) {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                    } else if (data.inventorySpecification.length >= 10) {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
                    } else if (data.inventorySpecification.length >= 16) {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 6);
                    } else if (data.inventorySpecification.length >= 20) {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 5);
                    } else {
                        LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                    }
                    LODOP.SET_PRINT_STYLEA(0, "OverFlow", 'hidden');
                    LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                    LODOP.ADD_PRINT_TEXT(226, 112, 115, 27, data.mainUnitName ? data.mainUnitName : data.unitName);//计量单位
                    LODOP.SET_PRINT_STYLEA(0, "FontName", "幼圆");
                    LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
                    LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
                }
            }
        },




    },
};
</script>
<style lang="less" scoped>
    /deep/.ant-tree-title {
        max-width: none !important;
    }
    .form-inline label {
        justify-content: left !important;
    }
    .form-inline > .col {
        margin-bottom: 1.5rem !important;
    }
    // .icons-list >>> .anticon {
    //   margin-right: 8px;
    //   font-size: 16px;
    // }
    .ant-advanced-search-form {
        padding: 24px;
        background: #fbfbfb;
        .ant-input-suffix {
            display: none;
        }
    }

    .ant-advanced-search-form .ant-form-item {
        display: flex;
        margin-bottom: 0px !important;
    }

    .ant-advanced-search-form .ant-form-item-control-wrapper {
        flex: 1;
    }

    .ant-advanced-search-form .card-wrapper {
        padding: 0px;
        margin-top: -17px;
    }

    #components-form-demo-advanced-search .ant-form {
        max-width: none;
    }
    #components-form-demo-advanced-search .search-result-list {
        margin-top: 16px;
        background-color: #fafafa;
        min-height: 200px;
        text-align: center;
        padding-top: 80px;
    }
</style>
<style lang="less">
    @import '~@/style/setting/inventory.less';
    .input-warn {
        border: 1px solid red !important;
    }
    .unitGroupTable {
        width: 100%;
        min-height: 200px;
    }
    .archives-flag {
        .ant-modal-body {
            padding: 0;
        }
        .ant-modal-footer {
            border-top: none;
        }
    }

    .archives-flag .ant-tabs-bar {
        border-bottom: 1px solid rgba(173, 173, 173, 0.5) !important;
    }
    .archives-flag .card-wrapper {
        .content {
            min-height: 260px;
        }
    }
    .ant-advanced-search-form {
        .ant-form-item {
            margin-bottom: 0px;
        }
    }
    .resize-table-container {
        overflow-y: auto;
        .ant-table-tbody {
            cursor: pointer;
        }
    }
    .input-group-before {
        cursor: not-allowed;
        background: #eee;
        text-align: right;
        padding-right: 0px;
        flex: 0 0 40px;
        border: 1px solid #a0a0a0;
        line-height: 29px;
        padding-top: 1px;
    }
    .ant-input-number,
    .ant-input-number-input {
        height: 32px !important;
        padding-left: 0;
    }
    .ant-input-number-handler-wrap {
        display: none;
    }
    .input-group-after {
        border-left: none;
        padding-left: 0px;
        flex: auto;
    }
    .input-group-after:focus {
        box-shadow: none;
    }
    .archive-tree-refresh {
        text-align: center;
        width: 32px;
        height: 32px;
        line-height: 29px;
        position: absolute;
        z-index: 10;
        right: 10px;
        cursor: pointer;
    }
    .archive-tree-refresh:hover {
        transition: all 1s;
        transform: rotate(180deg);
    }
    .page-input {
        height: 24px !important;
        .ant-input-number-input {
            height: 24px !important;
            line-height: 24px;
        }
    }
    .good-attr-wrapper {
        height: 300px;
        overflow-y: auto;
    }
    .add-good-attr {
        margin: 5px;
        margin-left: 75px;
        height: 32px;
        width: 320px;
        text-align: cnter;
        background: #1890ff;
        line-height: 32px;
        font-size: 24px;
        color: #fff;
        cursor: pointer;
    }
    .delete-good-attr {
        color: #fff;
        font-size: 24;
        background: #ff4d4f;
        width: 20px;
        height: 20px;
        line-height: 20px;
        margin-top: 5px;
        text-align: center;
        cursor: pointer;
    }
    .archives-barcode-box {
        width: 280px;
        margin: 0px auto;
        border: 2px solid #000;
        font-family: '幼圆';
        font-size: 13px;
        .company-name {
            font-weight: bold;
            text-align: center;
            height: 32px;
            color: #000;
            letter-spacing: 1px;
            line-height: 32px;
            width: 100%;
            border-bottom: 1px solid #000;
        }
        .bar-name {
            border-right: 1px solid #000;
            flex: 0 0 75px;
        }
        .bar-text {
            margin-left: 5px;
        }
        .bar-text-min {
            width: 76px;
            overflow: hidden;
        }
        .barcode-item {
            display: flex;
            font-weight: bold;
            padding: 0 5px;
            border-bottom: 1px solid #000;
            height: 32px;
            color: #000;
            letter-spacing: 1px;
            line-height: 32px;
        }
        .barcode-bottom {
            .barcode-left-wrapper {
                width: 60%;
                float: left;
            }
            .barcode-left {
                display: flex;
                font-weight: bold;
                padding: 0 5px;
                border-bottom: 1px solid #000;
                height: 32px;
                color: #000;
                letter-spacing: 1px;
                line-height: 32px;
                .bar-name {
                    border-right: 1px solid #000;
                    flex: 0 0 75px;
                }
            }
            .borcode-box {
                text-align: center;
                width: 40%;
                border-left: 1px solid #000;
                height: auto;
                float: right;
            }
        }
    }
    .barcode-btn {
        margin: 20px auto;
        text-align: center;
    }
</style>

<style lang="less" scoped>
    .ant-input-suffix {
        display: none;
    }
</style>